package com.jjclub.controller.system;

import com.jjclub.entity.JjclubRole;
import com.jjclub.mapper.JjclubRoleMapper;
import com.jjclub.service.system.RoleService;
import com.jjclub.vo.JjClubRoleVO;
import com.jjclub.vo.ResponseVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Arg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;

@Controller
@RequestMapping("/roleAction")
public class RoleController {


    @Autowired
    private RoleService roleService;
    @GetMapping("roleList")
    @ResponseBody
    public ResponseVO roleList(Integer page,Integer limit){
        ResponseVO responseVO =roleService.roleList(page, limit);
        return responseVO;
    }

    @GetMapping("page/roleList")
    public String roleList(){
        return "service/role/roleList";
    }
    @GetMapping("page/roleAdd")
    public String addRole(Model model){
        return "service/role/add";
    }

    @PostMapping("roleAdd")
    @ResponseBody
    public ResponseVO addRole(JjclubRole jjClubRole){
        System.out.println(jjClubRole);
        ResponseVO responseVO = roleService.RoleAdd(jjClubRole);
        return responseVO;
    }

    @GetMapping("/page/roleEdit/{roleid}")
    public String roleEdit(@PathVariable("roleid")String roleid,Model model){
        JjclubRole role = roleService.getJjclubRoleByid(roleid);
        model.addAttribute("role",role);
        return "service/role/edit";
    }

    @PostMapping("roleEdit")
    @ResponseBody
    public ResponseVO editRole(JjclubRole jjClubRole){
        System.out.println(jjClubRole);
        ResponseVO responseVO = roleService.editRole(jjClubRole);
        return responseVO;
    }


    @DeleteMapping("roleDel/{id}")
    @ResponseBody
    public ResponseVO roleDel(@PathVariable("id")String id){
        ResponseVO responseVO = roleService.roleDel(id);
        return responseVO;
    }
}
